package com.yeyouluo.mr;


import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class WordCountMapper extends Mapper<Object, Text, Text, IntWritable> {
    private static final IntWritable one = new IntWritable(1);

    @Override
    protected void map(Object key, Text value, Context context) throws IOException, InterruptedException {
        // 1. text --> string
        String str = value.toString().trim();
        // 2. blanksapce split
        String[] words = str.split(" ");
        // 3. output
        for (String word : words) {
            context.write(new Text(word), one);
        }
    }
}
